﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>URL类型查看</title>
    <link href="~/layui-v2.4.5/layui/css/layui.css" rel="stylesheet" />
    <script src="~/layui-v2.4.5/layui/layui.js"></script>
    <script src="~/Scripts/jquery-3.3.1.min.js"></script>
</head>
<body>

    <fieldset class="layui-elem-field">
        <legend>数据维护</legend>
        <div class="layui-field-box">

            <div class="layui-form">
                <input id="UrlTypeId" type="hidden" value="0" />
                <div class="layui-form-item">
                    <label class="layui-form-label">名称：</label>
                    <div class="layui-input-inline">
                        <input id="UrlTypeName" autocomplete="off" class=" layui-input" type="text" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">简介：</label>
                    <div class="layui-input-block">
                        <input id="UrlTypeContent" autocomplete="off" class=" layui-input" type="text" />
                    </div>
                </div>

                <div class="layui-btn-group layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <button id="btn_AddAndUpd" class="layui-btn" type="button"><i class="layui-icon">&#xe654;</i>保存</button>
                    </div>
                </div>
            </div>

        </div>
    </fieldset>




    <div id="divUrlList" class="layui-row" style="padding-left:1%">
        <div class="layui-col-xs6 layui-col-md12">
            <div class="grid-demo grid-demo-bg2">
                <table class="layui-hide" id="tableUrlTypeList" lay-filter="tableUrlTypeList"></table>
            </div>
        </div>
    </div>

    <script type="text/html" id="caozuo">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="del">删除</a>
    </script>
</body>
</html>


<script>

    layui.use(['table', 'layer', 'form', 'laydate', 'upload'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        form.render();
        //$(".btn-seach").click(function () {
        //    table.reload('tableTCustomer', {
        //        where: {
        //            seach_Customer: $("#seach_Customer").val(),
        //            seach_FactoryId: $("#seach_FactoryId").val(),
        //        }
        //    })
        //})

        //执行一个 table 实例
        table.render({
            elem: '#tableUrlTypeList',
            url: '/Url/GetReportUrlTypeList',
            //where: {
            //    seach_TypeId: $("#seach_UrlType").val(),
            //    seach_UrlLike: $("#seach_UrlLike").val(),
            //},
            method: 'post',
            //height: 300,
            width: 695,
            //limit: 20,
            //page: true,
            cols: [[
                { field: 'RowNum', width: 80, sort: true, fixed: 'left', title: '序号' },
                { field: 'TypeName', width: 110, title: '类型名称' },
                { field: 'TypeContent', width: 200, title: '简介' },
                { field: 'TypeCreateTimeStr', width: 175, title: '创建时间' },
                { fixed: 'right', width: 120, align: 'left', toolbar: '#caozuo', title: '操作' },
            ]]
        });

        //右侧工具栏事件
        table.on('tool(tableUrlTypeList)', function (obj) {
            //获取当前行的数据
            var data = obj.data;
            //序列化成json
            //var result = JSON.stringify(data);
            //判断 lay-event 中的值是否匹配
            if (obj.event === 'del') {
                layer.confirm('确定要删除吗？', { skin: 'layui-layer-molv', closeBtn: 1, icon: 3, anim: 4 }, function () {
                    $.ajax({
                        type: "post",
                        url: "/Url/DelUrlTypeById",
                        data: {
                            TypeId: data.TypeId,
                        },
                        success: function (result) {
                            if (result.Code == 1) {
                                layer.msg("删除成功", { icon: 1 })
                                //  obj.del();
                            }
                            else if (result.Code == 2) {
                                layer.msg("该数据在使用中。不可删除！", { icon: 2 })
                            }
                            else {
                                layer.alert("删除失败，提示：" + result.Msg, { icon: 2 })
                            }
                            layui.use('table', function () {
                                var table = layui.table;
                                table.reload('tableUrlTypeList')
                            })
                        },
                        error: function (falus) {
                            layer.msg("删除失败，错误提示" + falus)
                        }
                    })
                });
            } else if (obj.event === 'edit') {
                $("#UrlTypeId").val(data.TypeId);
                $("#UrlTypeName").val(data.TypeName);
                $("#UrlTypeContent").val(data.TypeContent);
            }
        })

    })

    $("#btn_AddAndUpd").click(function () {
        var UrlTypeId = $("#UrlTypeId").val(),
            UrlTypeName = $("#UrlTypeName").val(),
            UrlTypeContent = $("#UrlTypeContent").val();

        if (UrlTypeName == '') {
            layer.tips('名称不可为空！！！', '#UrlTypeName', { tips: [1, '#3595CC'], time: 2000 });
        } else if (UrlTypeContent == '') {
            layer.tips('简介不可为空！！！', '#UrlTypeContent', { tips: [1, '#3595CC'], time: 2000 });
        } else {
            $.ajax({
                type: "post",
                data: {
                    TypeName: UrlTypeName,
                    TypeContent: UrlTypeContent,
                    TypeId: UrlTypeId
                },
                url: "/Url/AddAndUpdateUrlType",
                success: function (result) {
                    if (result.Code == 1) {
                        layer.msg("保存成功", { icon: 1 });
                        $("#UrlTypeName").val('');
                        $("#UrlTypeContent").val('');
                        $("#UrlTypeId").val(0);
                    }
                    else if (result.Code == 2) {
                        layer.msg("此名称已存在不可重复保存", { icon: 2 });
                    }
                    else {
                        $("#UrlTypeId").val(0);
                        layer.alert("数据保存失败，提示：" + result.Msg, { icon: 2 });
                    }

                    layui.use('table', function () {
                        var table = layui.table;
                        table.reload('tableUrlTypeList')
                    })

                }
            })
        }
    })


</script>